<?php
import( 'de.ceus-media.file.log.LogFile' );
/**
 *	eMail Sender.
 *	@package		tools.BugTracker
 *	@uses			LogFile
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@since			01.11.2005
 *	@version		1.0
 */
/**
 *	eMail Sender.
 *	@package		tools.BugTracker
 *	@uses			LogFile
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@since			01.11.2005
 *	@version		1.0
 */
class MailSender
{
	/**	@var		$registry		ADT_Registry		Object Registry */
	var $registry;
	
	/**
	 *	Constructor.
	 *	@access		public
	 *	@return		void
	 */
	function MailSender()
	{
		$this->registry	= ADT_Registry::getInstance();
	}	

	/**
	 *	Sends eMail between two existing Users.
	 *	@access		public
	 *	@param		int		$from		ID of User
	 *	@param		int		$to			ID of User
	 *	@return		bool
	 */
	function sendMail( $from, $to, $subject, $body )
	{
		$config	= $this->registry->get( 'config' );
		
		$user	= new User( $from );
		$source	= $user->getData( false, true );

		$user	= new User( $to );
		$target	= $user->getData( false, true );
		$log		= new LogFile( $config['config']['log_path']."emails.log" );
		$headers	= "From: ".$source['username']." <".$source['email'].">\n\r";
		if( mail( $target['email'], $subject, $body, $headers ) )
		{
			$log->addEntry( "Mail from ".$source['username']." <".$source['email']."> to ".$target['username']." <".$target['email']."> has been sent." );
			return true;
		}
		$log->addEntry( "Mail from ".$source['username']." to ".$target['username']." has been failed." );
		return false;
	}
}
?>